using System;

namespace BillsDomain
{
    public class PaymentWithDate : Payment, IComparable
    {
        public DateTime PaymentDate { get; set; }
        public decimal Balance { get; set; }

        #region IComparable Members

        public override int CompareTo(object obj)
        {
            PaymentWithDate otherAsPaymentDate = obj as PaymentWithDate;
            if (otherAsPaymentDate == null)
            {
                throw new ArgumentException("obj is not a PaymentOnDate");
            }

            if (otherAsPaymentDate.PaymentDate == this.PaymentDate)
            {
                if (otherAsPaymentDate.IsDebit == this.IsDebit)
                {
                    return 0;
                }
                else if (this.IsDebit && !otherAsPaymentDate.IsDebit)
                {
                    //this is debit and the other is credit so this comes after
                    return 1;
                }
                else
                {
                    // this is credit and other is debit so this comes first
                    return -1;
                }
            }
            else
            {
                return this.PaymentDate.CompareTo(otherAsPaymentDate.PaymentDate);
            }
        }

        #endregion
    }
}
